#ifndef CONTROLLERZONE_H
#define CONTROLLERZONE_H

#include <stdint.h>
#include "ColorUtils.h"
//#include "RGBController.h"
//#include "json.hpp"

//using json = nlohmann::json;

class ControllerZone
{

public:

    ControllerZone(unsigned int zone_idx, bool reverse, uint16_t rgbw, uint16_t rgbh);//:
    /*    zone_idx(zone_idx),
        reverse(reverse)
    {
    };*/
    ~ControllerZone();

    //RGBController* controller;
    unsigned int zone_idx;
    bool reverse;
private:
    const uint16_t RGBW;
    const uint16_t RGBH;

public:
    zone_type type()
    {
        return ZONE_TYPE_MATRIX;//controller->zones[zone_idx].type;
    }

    unsigned int start_idx()
    {
        return 0;//controller->zones[zone_idx].start_idx;
    }

    unsigned int size()
    {
        return RGBW*RGBH;//type() == ZONE_TYPE_MATRIX ?
               //     controller->zones[zone_idx].matrix_map->width *
               // controller->zones[zone_idx].matrix_map->height : leds_count();
    }

    unsigned int matrix_size()
    {
        return RGBW*RGBH;//controller->zones[zone_idx].matrix_map->width *
                //controller->zones[zone_idx].matrix_map->height;
    }

    unsigned int leds_count()
    {
        return RGBW*RGBH;//controller->zones[zone_idx].leds_count;
    }

    unsigned int matrix_map_width()
    {
        return RGBW;//controller->zones[zone_idx].matrix_map->width;
    }

    unsigned int matrix_map_height()
    {
        return RGBH;//controller->zones[zone_idx].matrix_map->height;
    }

    unsigned int* map();
    /*{
        return RGBMap;
    }*/

//    bool operator==(ControllerZone const & rhs) const
//    {
//        return this->controller == rhs.controller && this->zone_idx == rhs.zone_idx;
//    }

//    bool operator<(ControllerZone const & rhs) const
//    {
//        // whatever
//        return this->controller != rhs.controller || this->zone_idx != rhs.zone_idx;
//    }

//    std::string display_name()
//    {
//        return controller->name + " " +  std::to_string(zone_idx);
//    }

//    json to_json()
//    {
//        json j;
//        j["zone_idx"] = zone_idx;
//        j["reverse"] = reverse;
//        j["name"] = controller->name;
//        j["location"] = controller->location;
//        j["serial"] = controller->serial;
//        j["description"] = controller->description;
//        j["version"] = controller->version;
//        j["vendor"] = controller->vendor;
//        return j;
//    }

    void SetAllZoneLEDs(RGBColor color, int brightness);
    /*{
        //controller->SetAllZoneLEDs(zone_idx, ColorUtils::apply_brightness(color, brightness / 100.f));
        for(int idx=0; idx<(sizeof(RGBMap)/sizeof(RGBMap[0])); idx++) RGBMap[idx] = color;
    }*/

    void SetLED(int idx, RGBColor color, int brightness);
    void SetLED(int x, int y, RGBColor color, int brightness);
    uint32_t GetLED(int x, int y);
    /*{
         //controller->SetLED(idx, ColorUtils::apply_brightness(color, brightness / 100.f));
        RGBMap[idx] = color;
    }*/
};

#endif // CONTROLLERZONE_H
